package com.cloudsigns.factorymanager2.project.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.project.adapter.ProductInformationAdapter;
import com.cloudsigns.factorymanager2.project.adapter.ProductReworkAdapter;
import com.cloudsigns.factorymanager2.project.bean.ProductBean;
import com.cloudsigns.factorymanager2.project.bean.ProductReworkBean;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 产品质检单
 * Created by tony on 2017/12/20.
 */

public class QualityInspectionOrderActivity extends Activity implements View.OnClickListener {
    private ImageView img_back;
    private TextView tv_title;
    private TextView btn_processing_results;
    private TextView btn_confirm_handle;
    private RelativeLayout rl_product_name;
    private ListView lv;
    private ProductReworkAdapter adapter;
    private List<ProductReworkBean> productReworkBeanList = new ArrayList<>();
    private final String TAG = "QualityInspectionOrderActivity";


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_quality_inspection_list);

        init();
    }


    private void init() {
        img_back = findViewById(R.id.img_back);
        tv_title = findViewById(R.id.tv_title);
        btn_processing_results = findViewById(R.id.btn_processing_results);
        btn_confirm_handle = findViewById(R.id.btn_confirm_handle);
        rl_product_name = findViewById(R.id.rl_product_name);
        lv = findViewById(R.id.lv);

        tv_title.setText(getResources().getText(R.string.quality_inspection_list));
        img_back.setOnClickListener(this);
        btn_processing_results.setOnClickListener(this);
        btn_confirm_handle.setOnClickListener(this);
        rl_product_name.setOnClickListener(this);


        adapter = new ProductReworkAdapter(this, TAG);
        adapter.setData(productReworkBeanList);
        lv.setAdapter(adapter);

    }

    private void onfirmHandle() {
        Toast.makeText(this, "处理成功", Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    public void onClick(View view) {
        Intent mIntent;
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.btn_processing_results:
                mIntent = new Intent(QualityInspectionOrderActivity.this, ProductQualityCheckbackProcessingActivity.class);
                startActivityForResult(mIntent, ConstantUtil.PRODUCT_QUALITY_CHECKBACK_PROCESSING);
                break;
            case R.id.btn_confirm_handle:
                onfirmHandle();
                break;
            case R.id.rl_product_name:

                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case ConstantUtil.PRODUCT_QUALITY_CHECKBACK_PROCESSING: //产品质检退回处理
                if (data != null) {
                    boolean bool = data.getBooleanExtra(ConstantUtil.PRODUCTREWORKBEAN, false);
                    if (bool) {

                        productReworkBeanList.add(new ProductReworkBean(ConstantUtil.TYPE_REWORK, 3, "2017-12-31"));
                        adapter.setData(productReworkBeanList);
                        adapter.notifyDataSetChanged();

                    }

                }
                break;
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}
